
	layui.use(['form','layer','jquery'],function(){
		var form = layui.form,
		layer = layui.layer,
		$ = layui.$;
		
		//自定义校验密码
		form.verify({
			password: [
    					/^[\S]{6,12}$/
    					,'密码必须6到12位，且不能出现空格'
  		] 
		});
		
		//实时校验手机号是否注册
		$('#cellphone').blur(function(){
    	var phone = $('#cellphone').val();//获得手机号
    	$.ajax({
    		type:"POST",
    		url:urlHead + "/user/verifyMobile",
    		async:true,
    		data:{"mobile":phone},
    		success:function(res){
    			console.log(res);
    			if(res.code==500215){
    				layer.msg('该手机号已被注册',{icon:5});
    				return false;
    			}
    		},
    		dataType:"json"
    	});
    });
		
		//提交表单
		form.on('submit(LAY-user-reg-submit1)',function(obj){
			var field = obj.field,
		    cellphone = field.cellphone,								//手机号
		    inputpass = field.password,									//密码
		    inputrepass = field.repass,									//确认密码
		    vercode = field.vercode,									//短信验证码
		    email = field.email;										//邮箱
 			console.log(inputpass);
 			
      //确认密码
      if(inputpass !== inputrepass){
				layer.msg('两次密码输入不一致');
				return false;
      }else{//md5加密
      	var salt = g_passsword_salt;
		var strpass = ""+salt.charAt(2)+salt.charAt(3)+salt.charAt(1)+inputpass + salt.charAt(6)+salt.charAt(7);
		var strrepass = ""+salt.charAt(2)+salt.charAt(3)+salt.charAt(1)+inputrepass + salt.charAt(6)+salt.charAt(7);
      	var password = $.md5(strpass);
      	var repass = $.md5(strrepass);
      }
      console.log(password);
      console.log(repass);
      //是否同意用户协议
      if(!field.agreement){
				layer.msg('你必须同意用户协议才能注册');
      }
      
      //请求
      $.ajax({
      	type:"POST",
      	url:urlHead + "/user/doRegisterStep1",
      	async:true,
      	data:{
      		"mobile":cellphone,
        	"password":password,
        	"passwordAgain":repass,
        	"verificationCode":vercode,
        	"email":email
      	},
      	success:function(res){
      		console.log(res);
      		console.log(res.data);
      		if(res.code==0){
      				layer.msg('第一步成功',
      						  {icon:6,time:3000},
      						  function(){//要把页面跳转写到msg的函数里面，不然会立即跳转
      							location.href = "user_register2_new.html?uuid="+res.data;	
      				});
        		}else{
        			layer.msg(res.msg,{icon:5});
        		}
      	},
      	error:function(){
			layer.msg('注册失败',{icon:5});
       },
       dataType:"json"
      });
      
      return false;
		});
		
	});